/**
 * 校验表单
 */
import { Pattern } from '@/utils/pattern'

// 登录信息
export const loginRules = {
  username: [
    {
      required: true,
      message: '请输入账号',
      trigger: 'blur'
    }
  ],
  password: [
    {
      required: true,
      message: '请输入密码',
      trigger: 'blur'
    }
  ]
}
// 修改密码
export const changePasswordRules = {
  originPassword: [
    {
      required: true,
      message: '请输入原始密码',
      trigger: 'blur'
    }
  ],
  finalPassword: [
    {
      required: true,
      message: '请输入新密码',
      trigger: 'blur'
    }
  ]
}
// map字典
export const mapRules = {
  value: [
    {
      required: true,
      message: '请输入名称',
      trigger: 'blur'
    }
  ]
}
// 项目信息
export const projectInfoRules = {
  projectName: [
    {
      required: true,
      message: '项目名称不能为空',
      trigger: 'blur'
    }
  ],
  projectNum: [
    {
      required: true,
      message: '项目编号不能为空',
      trigger: 'blur'
    }
  ],
  mapId: [
    {
      required: true,
      message: '请选择项目分类',
      trigger: 'blur'
    }
  ],
  beginTime: [
    {
      required: true,
      message: '开始时间不能为空',
      trigger: 'change'
    }
  ]
}
// 用户信息
export const userInfoRules = {
  username: [
    {
      required: true,
      message: '用户名不能为空',
      trigger: 'blur'
    },
    {
      max: 20,
      min: 2,
      message: '账号2-20位',
      trigger: 'blur'
    }
  ],
  password: [
    {
      required: true,
      message: '密码不能为空',
      trigger: 'blur'
    }
  ],
  trueName: [
    {
      required: true,
      message: '真实姓名不能为空',
      trigger: 'blur'
    },
    {
      max: 4,
      min: 2,
      message: '真实姓名2-4位',
      trigger: 'blur'
    }
  ],
  sex: [
    {
      required: true,
      message: '请选择性别',
      trigger: 'change'
    }
  ],
  phone: [
    {
      required: true,
      message: '手机号不能为空',
      trigger: 'blur'
    },
    {
      validator: (rule, value, callback) => {
        if (!Pattern.phone.test(value)) {
          callback(new Error('手机号格式不正确！'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ],
  email: [
    {
      required: true,
      message: '邮箱不能为空',
      trigger: 'blur'
    },
    {
      validator: (rule, value, callback) => {
        if (!Pattern.email.test(value)) {
          callback(new Error('邮箱格式不正确！'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ],
  inductionTime: [
    {
      required: true,
      message: '入职时间不能为空',
      trigger: 'change'
    }
  ]
}
// 资源信息
export const resourceInfoRules = {
  menuType: [
    {
      required: true,
      message: '请选择资源类型',
      trigger: 'blur'
    }
  ],
  name: [
    {
      required: true,
      message: '资源标识不能为空',
      trigger: 'blur'
    }
  ],
  label: [
    {
      required: true,
      message: '资源名称不能为空',
      trigger: 'blur'
    }
  ],
  url: [
    {
      required: true,
      message: '资源路径不能为空',
      trigger: 'blur'
    }
  ],
  ico: [
    {
      required: true,
      message: '请选择资源图标',
      trigger: 'blur'
    }
  ],
  sort: [
    {
      required: true,
      message: '请选择资源排序',
      trigger: 'blur'
    }
  ]
}
